package com.zzh.structuredeployment.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import com.zzh.bridge.page.PageApp
import com.zzh.bridge_annotation.RouteTag
import android.widget.ImageView
import androidx.fragment.app.Fragment
import com.zzh.custom.PictureBrowseView
import com.zzh.custom.PictureBrowseView.Rely
import com.zzh.structuredeployment.R
import kotlinx.android.synthetic.main.activity_four.*


@RouteTag(PageApp.FOUR)
class FourActivity : AppCompatActivity() {

    private var count = 0;
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_four)
        addAnimtorView()
        add.setOnClickListener{
            count++
            viewAnimtor.displayedChild = count % viewAnimtor.childCount
        }

        getIntentData()

        pictureBrowseView.setConfig(object : PictureBrowseView.Config {
            override fun getShowPosition(): Int {
                return mPsition
            }

            override fun getList(): List<Map<String, String>>? {
                return listData!!
            }

            override fun newFragment(): Fragment? {
                return null
            }

        }).setRely(object : Rely {
            override fun load(imageView: ImageView?, drawId: Int) {
                imageView?.setImageResource(drawId)
            }

            override fun load(
                imageView: ImageView,
                path: String?,
                smallPath: String?
            ) {

            }
        }).show()

    }

    private fun addAnimtorView() {
        for (i in 0..10) {
            viewAnimtor.addView(createView(">>>${i}>>>"))
        }
    }

    private fun createView(s: String): View {
        var view = TextView(this)
        var layoutParams = LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )
        view.text = s
        view.layoutParams = layoutParams
        view.gravity = Gravity.CENTER
        return view
    }




    var listData: List<Map<String, String>>? = null
    var mPsition = 0

    private fun getIntentData() {
        val intent = intent
        intent?.let {
            listData = intent.getSerializableExtra("data") as List<Map<String, String>>
            mPsition = intent.getIntExtra("position", 0)
        }
    }

}